﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NinjaToolbox.PhysicsSystem;

public class CheckSphereBoxCapsule : MonoBehaviour
{
    public enum EType { Sphere, Box, Capsule }
    public float radius = 1f;
    public Vector3 size = new Vector3(1f, 1f, 2f);
    public float height = 1f;
    public int virtualSegment = 3;
    public EType type;
    bool mIsHit;


    void Update()
    {
        switch (type)
        {
            case EType.Sphere:
                mIsHit = PhysicsUtil.CheckSphere(transform.position, radius);
                break;
            case EType.Box:
                mIsHit = PhysicsUtil.CheckBox(transform.position, size, transform.rotation);
                break;
            case EType.Capsule:
                mIsHit = PhysicsUtil.CheckCapsule(transform.position, radius, height, virtualSegment);
                break;
            default:
                break;
        }
    }

    void OnDrawGizmos()
    {
        var cacheMatrix = Gizmos.matrix;
        var cacheColor = Gizmos.color;
        Gizmos.color = mIsHit ? Color.red : Color.white;
        Gizmos.matrix = transform.localToWorldMatrix;

        switch (type)
        {
            case EType.Sphere:
                Gizmos.DrawWireSphere(Vector3.zero, radius);
                break;
            case EType.Box:
                Gizmos.DrawWireCube(Vector3.zero, size);
                break;
            case EType.Capsule:
                Gizmos.DrawWireCube(Vector3.zero, Vector3.one * radius);
                break;
        }

        Gizmos.color = cacheColor;
        Gizmos.matrix = cacheMatrix;
    }
}
